package at.fhj.swd.pse.entities;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

@Entity
@Table(name = "Activities")
public class Activity implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = -9106147052521264639L;

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "ID")
	private int m_id;

	@NotNull
	@Size(min = 1, max = 2048)
	@Column(name = "Text")
	private String m_text;

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "Timestamp")
	private Date m_timestamp;

	@ManyToOne
	@JoinColumn(name = "FK_Creator")
	private User m_creator;

	@Enumerated(EnumType.STRING)
	@Column(name = "Type")
	private EActivityType m_type;

	public int getId() {
		return this.m_id;
	}

	public void setId(final int id) {
		this.m_id = id;
	}

	public String getText() {
		return this.m_text;
	}

	public void setText(final String text) {
		if (text != null) {
			this.m_text = text;
		} else {
			throw new NullPointerException();
		}
	}

	public Date getTimestamp() {
		return this.m_timestamp;
	}

	public void setTimestamp(final Date timestamp) {
		if (timestamp != null) {
			this.m_timestamp = timestamp;
		} else {
			throw new NullPointerException();
		}

	}

	public User getCreator() {
		return this.m_creator;
	}

	public void setCreator(final User creator) {
		if (creator != null) {
			this.m_creator = creator;
		} else {
			throw new NullPointerException();
		}
	}

	public EActivityType getType() {
		return this.m_type;
	}

	public void setType(final EActivityType type) {
		this.m_type = type;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((m_creator == null) ? 0 : m_creator.hashCode());
		result = prime * result + m_id;
		result = prime * result + ((m_text == null) ? 0 : m_text.hashCode());
		result = prime * result
				+ ((m_timestamp == null) ? 0 : m_timestamp.hashCode());
		result = prime * result + ((m_type == null) ? 0 : m_type.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Activity other = (Activity) obj;
		if (m_creator == null) {
			if (other.m_creator != null)
				return false;
		} else if (!m_creator.equals(other.m_creator))
			return false;
		if (m_id != other.m_id)
			return false;
		if (m_text == null) {
			if (other.m_text != null)
				return false;
		} else if (!m_text.equals(other.m_text))
			return false;
		if (m_timestamp == null) {
			if (other.m_timestamp != null)
				return false;
		} else if (!m_timestamp.equals(other.m_timestamp))
			return false;
		if (m_type != other.m_type)
			return false;
		return true;
	}	
}
